//
//  ByUISceneHistoryCell.m
//  laserdevice_ios
//
//  Created by pro on 16/12/14.
//  Copyright © 2016年 com.itboye. All rights reserved.
//

#import "ByUISceneHistoryCell.h"

@implementation ByUISceneHistoryCell
{
    UIImageView *_imageView;        // 图片
    UILabel     *_nameLabel;        // 名称
    UILabel     *_updateLabel;      // 更新时间
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    UILongPressGestureRecognizer *lp = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(delete:)];
    
    [self.contentView addGestureRecognizer:lp];
    
    // 主图
    _imageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageView];
    
    // 名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.adjustsFontSizeToFitWidth = YES;
    _nameLabel.font = FONT(16);
    _nameLabel.textColor = [UIColor blackColor];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nameLabel];
    
    // 更新
    _updateLabel = [[UILabel alloc] init];
    _updateLabel.numberOfLines = 2;
    _updateLabel.font = FONT(12);
    _updateLabel.textColor = [UIColor grayColor];
    _updateLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_updateLabel];
   
}

- (void)setJsonDic:(NSDictionary *)jsonDic {
    
    _jsonDic = jsonDic;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _imageView.frame    = CGRectMake(0, 0, 50, 50 / 6 * 7);
    _nameLabel.frame    = CGRectMake(0, 0, self.width / 2, 25);
    _updateLabel.frame  = CGRectMake(0, 0, _nameLabel.width, 30);
    
    
    CGFloat remineX = (self.width - _imageView.width - _nameLabel.width) / 2;
    _imageView.left = remineX;
    _nameLabel.left = _imageView.right + remineX / 2 / 2;
    _updateLabel.left = _nameLabel.left;
    
    CGFloat remineY = (self.height - _imageView.height) / 2;
    _imageView.top = remineY;
    _nameLabel.top = _imageView.top;
    _updateLabel.top = _nameLabel.bottom;

    NSString *source_type = _jsonDic[@"source_type"];
    if ([source_type isEqualToString:@"PDF"]) {
        _imageView.image = [UIImage imageNamed:@"scene_history_pdf"];
    } else {
        _imageView.image = [UIImage imageNamed:@"scene_history_ld"];
    }

    _nameLabel.text = _jsonDic[@"name"];
    _updateLabel.text = [NSString stringWithFormat:@"%@%@", _jsonDic[@"create_time"], STRING(@"gengxin")];
}


- (void)delete:(UILongPressGestureRecognizer *)lp {
    
    if (lp.state == UIGestureRecognizerStateBegan) {
        
        if (self.delectAction) {
            self.delectAction();
        }
    }
}



@end
